var requestService = require('../../utils/requestService.js');
var app=getApp();
Page({
    data: {
        paymentDetail:{
        },
        errMsg:'',
        orderNo:'',
        paymentImmediateBt:{
            disabled: false,
            loading: false
        }
    },
    // 页面加载
    onLoad: function (options) {
        // 设置本页导航标题
        wx.setNavigationBarTitle({
            title: '支付详情'
        })
        const that = this;
        const orderNo = options.param1;
        const errMsg = options.errMsg;
        console.log(errMsg);
        requestService.sendGetRequest("/order/detail/" + orderNo,null,function (result) {
            that.setData({
                paymentDetail:result.data.resData,
                errMsg:errMsg,
                orderNo:orderNo
            })
        })
    },
    /**跳转到订单列表*/
    gotoOrders:function () {
        wx.redirectTo({
            url: '../order/index'
        })
    },
    /**立即支付*/
    paymentImmediate:function () {
        let that=this;
        that.paymentImmediateBtLoading();
        const orderNo=that.data.orderNo;//订单编号
            requestService.sendPostRequest("/payment/ewallet/topay/"+orderNo, null, function (result) {
                const resultData = result.data;
                that.paymentImmediateBtUnLoading();
                if( resultData.resCode == 0 && resultData.resData == true){
                    wx.redirectTo({
                        url: "../msg/msg_success?msg=订单支付成功&redirectUrl=../payment/payment_detail&btText=订单详情&param1="+orderNo
                    })
                }else{
                    wx.navigateTo({
                        url: '../msg/msg_fail?msg='+resultData.message
                    })
                }
            },function () {
                that.paymentImmediateBtUnLoading();

            });
    },
    /**按钮设置为加载、不可点击*/
    paymentImmediateBtLoading:function () {
        let that=this;
        that.setData({
            "paymentImmediateBt.disabled": true,
            "paymentImmediateBt.loading": true
        });
    },
    /**按钮取消加载、不可点击*/
    paymentImmediateBtUnLoading:function () {
        let that=this;
        that.setData({
            "paymentImmediateBt.disabled": false,
            "paymentImmediateBt.loading": false
        });
    }
})